/*
 * Copyright (c) 2010-2011 GOV.
 * [Id:FacesUtil.java  11-8-20 下午7:53 poplar.mumu ]
 */
package org.mumu.pawn.util;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * JSF工具类
 * </p>
 *
 * @author poplar.yfyang
 * @version 1.0 11-8-20 下午7:53
 * @since JDK 1.5
 */
public class FacesUtil {
    /**
     * 获取JSF参数，通过URL的方式。
     *
     * @param arg_name 参数名称
     * @return 参数值
     */
    public static String getViewParameter(String arg_name) {
        FacesContext fc = FacesContext.getCurrentInstance();
        String value = fc.getExternalContext().getRequestParameterMap().get(arg_name);
        return value != null && value.trim().length() > 0 ? value : null;
    }

    /**
     * 获取JSF上下文中的Session
     *
     * @return JSF上下文中的Session
     */
    public static HttpSession faceSession() {
        FacesContext fc = FacesContext.getCurrentInstance();
        return (HttpSession) fc.getExternalContext().getSession(false);
    }

    public static void sendMessage(String arg_msg) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR,
                        arg_msg, "提示信息"));
    }
    public static void sendMessage(FacesContext arg_context,String arg_msg) {
        arg_context.addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR,
                        arg_msg,"提示信息"));
    }

}
